﻿/*
 * Rappelz: Endless Odyssey - The first free open source Rappelz server emulator
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rappelz.GameServer.Network;
using System.Data.Common;
using System.Data;
using Rappelz.GameServer.Network.GameClient;

namespace Rappelz.GameServer.Database
{
    /// <summary>
    /// DB_UpdateRandomQuest (smp_insert_favor)
    /// </summary>
    public class DB_UpdateRandomQuest : IDBProc
    {
        private Player m_pPlayer;
        private int m_nOwnerID;
        private int m_nCode;
        private int m_nKey1;
        private int m_nKey2;
        private int m_nKey3;
        private int m_nValue1;
        private int m_nValue2;
        private int m_nValue3;
        private byte m_cDropped;


        public BaseObject m_CBObject = null;

        public DB_UpdateRandomQuest(Player pPlayer, int owner_id, int code, int key1, int key2, int key3, int value1, int value2, int value3, byte cIsDropped)
        {
            this.m_pPlayer = pPlayer;
            this.m_nOwnerID = owner_id;
            this.m_nCode = code;
            this.m_nKey1 = key1;
            this.m_nKey2 = key2;
            this.m_nKey3 = key3;
            this.m_nValue1 = value1;
            this.m_nValue2 = value2;
            this.m_nValue3 = value3;
            this.m_cDropped = cIsDropped;
        }

        public void SetCB(BaseObject obj)
        {
            m_CBObject = obj;
        }

        public void RunCB()
        {
            if (m_CBObject != null)
                m_CBObject.onEndQuery();
        }

        public bool onProcess()
        {
            DbConnection conn = GameDBManager.Instance.CreateConnection();
            DbCommand cmd = conn.CreateCommand();

            cmd.CommandText = "smp_update_random_quest";
            cmd.CommandType = CommandType.StoredProcedure;
            DbParameter IN_OWNER_ID = GameDBManager.Instance.CreateInParameter(cmd, "IN_OWNER_ID", DbType.Int32, this.m_nOwnerID);
            DbParameter IN_CODE = GameDBManager.Instance.CreateInParameter(cmd, "IN_CODE", DbType.Int32, this.m_nCode);
            DbParameter IN_KEY1 = GameDBManager.Instance.CreateInParameter(cmd, "IN_KEY1", DbType.Int32, this.m_nKey1);
            DbParameter IN_KEY2 = GameDBManager.Instance.CreateInParameter(cmd, "IN_KEY2", DbType.Int32, this.m_nKey2);
            DbParameter IN_KEY3 = GameDBManager.Instance.CreateInParameter(cmd, "IN_KEY3", DbType.Int32, this.m_nKey3);
            DbParameter IN_VALUE1 = GameDBManager.Instance.CreateInParameter(cmd, "IN_VALUE1", DbType.Int32, this.m_nValue1);
            DbParameter IN_VALUE2 = GameDBManager.Instance.CreateInParameter(cmd, "IN_VALUE2", DbType.Int32, this.m_nValue2);
            DbParameter IN_VALUE3 = GameDBManager.Instance.CreateInParameter(cmd, "IN_VALUE3", DbType.Int32, this.m_nValue3);
            DbParameter IS_DROPPED = GameDBManager.Instance.CreateInParameter(cmd, "IS_DROPPED", DbType.Byte, this.m_cDropped);
            conn.Open();

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Globals.Log.Error("DB_UpdateRandomQuest.onProcess Exception: {0}", ex);
            }
            conn.Close();

            return true;
        }
    }


}

